<template>
  <view>
    <view class="continer">
      
      <view v-if="(type == 1 && rcomment == null) || (type == 0 && ucomment == null)">
        <view class="c_box">
          <view class="c_top" style="height: 5rpx;"></view>
          <view class="context">
            <textarea class="c_context" v-model="inputValue" @blur="bindTextAreaBlur"  placeholder="请输入评价" />
          </view>
        </view>
        <view class="btn-settle" @click="commitComment">评价</view>
      </view>
      
      <view class="title">
        用户评价
      </view>
      <view class="comment" v-if="ucomment != null">
        {{ucomment}}
      </view>
      <view v-else>
        该用户暂无评价
      </view>
    </view>
    <view class="continer">
      <view class="title">
        配送者评价
      </view>
      <view class="comment" v-if="rcomment != null">
        {{rcomment}}
      </view>
      <view v-else>
        该用户暂无评价
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "my-estimate",
    data() {
      return {
        orderId: '',
        type: '',
        inputValue: '',
        rcomment: '',
        ucomment: '',
      };
    },
    onLoad(options) {
      this.orderId = options.orderId;
      this.type = options.type;
      console.log(options)
      this.getComment(this.orderId);
    },
    onPullDownRefresh() {
      this.getComment(this.orderId);
    },
    methods: {
      // 提交评价
      async commitComment(){
        
        if (this.inputValue.length < 4) {
          uni.$showMsg("内容至少大于4字")
          return;
        }
        
        const dataComment = {
          orderId: this.orderId,
          type: this.type,
          comment: this.inputValue
        }
        const {
          data: result
        } = await uni.$http.post('/api/READ/api/my/comment/push/comment', dataComment)
        if (result.code != 200) return uni.$showMsg(result.msg)
        uni.$showMsg("评价成功")
        console.log(result);
      },
      // 获取评价
      async getComment(orderId) {
        const {
          data: result
        } = await uni.$http.post('/api/READ/api/my/comment/get/comment/' + orderId)
        if (result.code != 200) return uni.$showMsg(result.msg)
        console.log(result);
        this.rcomment = result.data.rcomment;
        this.ucomment = result.data.ucomment;
        uni.stopPullDownRefresh() //停止刷新
      },
      bindTextAreaBlur: function(e) {
        this.inputValue = e.detail.value;
        console.log(this.inputValue)
      },
    }
  }
</script>

<style lang="scss">
  .btn-settle {
    height: 40px;
    width: 100px;
    background-color: #00AA00;
    color: white;
    line-height: 40px;
    text-align: center;
    padding: 0 10px;
    margin-bottom: 10%;
  }

  .continer {
    margin: 5%;
    margin-bottom: 20%;
  }

  .title {
    color: #00AA00;
    margin-bottom: 2%;
    font-size: 40rpx;
  }

  .comment {
    margin-top: 2%;
    width: 90%;
    display: inline-block;
    white-space: pre-wrap;
    word-wrap: break-word;
    height: auto;
    font-size: 35rpx;
  }

  .c_context {
    border-radius: 10rpx;
    margin: 10rpx;
  }

  .c_box {
    border-radius: 10rpx;
    margin: 1%;
    background-color: #F8F8FF;
  }
</style>